package org.wendu.wdoa.emp.api;

import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.wendu.wdoa.common.Result;
import org.wendu.wdoa.emp.dto.EmpDto;
import org.wendu.wdoa.emp.dto.EmpQueryDto;
import org.wendu.wdoa.emp.dto.MgrDto;
import org.wendu.wdoa.emp.dto.UserDto;
import org.wendu.wdoa.emp.model.Employee;
import org.wendu.wdoa.emp.service.EmployeeService;

import java.util.Map;


@RestController
@RequestMapping("/emp")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;
    @GetMapping ("")
    public Result empList(EmpQueryDto pageParam){
        Map<String,Object> page = employeeService.getEmployList(pageParam);
        return Result.OK(page);
    }
    @DeleteMapping("/emp")
    public Result empDoDel(String e_id){
            employeeService.deleteEmpById(e_id);
            return Result.OK();
    }
    @DeleteMapping("/empDel/{e_id}")
    public Result empDoDel2(@PathVariable String e_id){
        employeeService.deleteEmpById(e_id);
        return Result.OK();
    }
    @PostMapping ("")
    public Result empDoAdd(@RequestBody EmpDto empDto){
        employeeService.addOneEmp(empDto);
        return Result.OK();
    }
    @PostMapping("/emp_update")
    public Result empUpdate(@RequestBody Employee employee){
        employeeService.updateOneEmp(employee);
        return Result.OK();
    }
    @DeleteMapping("/emp-multi")
    public Result empDoDelMulti(@RequestBody String[] eids){
        employeeService.deleteEmpById(eids);
        return Result.OK();
    }
    @PostMapping("/addUser")
    public Result empAddUser(@RequestBody UserDto empDto){
        employeeService.addUser(empDto);
        return Result.OK();
    }
    @DeleteMapping("/delUser/{e_id}")
    public Result empDelUser(@PathVariable String e_id){
        employeeService.delUser(e_id);
        return Result.OK();
    }
    @PostMapping("/addMgr")
    public Result empAddMgr(@RequestBody MgrDto mgrDto){
        employeeService.addMgr(mgrDto);
        return Result.OK();
    }
    @DeleteMapping("/delMgr/{e_id}")
    public Result empDelMgr(@PathVariable String e_id){
        employeeService.delMgr(e_id);
        return Result.OK();
    }
}
